import requests
from loguru import logger

from config import ENV


# from config import ENV, JsonPath


class Base:
    HOST = ""
    def send_request(self, api_name, data:dict) -> requests.Response:
        if self.HOST:
            data.update({"url": self.HOST + data.get("url")})
        logger.info(f"接口 - ({api_name}) - 请求参数为:{data}")
        response = requests.request(**data)
        logger.info(f"接口 - ({api_name}) - 接口响应信息为:{response.text}")
        return response


class Login(Base):
    def __init__(self):

        self.HOST = ENV.HOST
        self.server_token = self.server_login()
        # self.path = JsonPath()

    def server_login(self):
        data = {
            "url":  "/adminapi/login?username=admin&password=123123",
            "method": "get"
        }

        return self.send_request(self.server_login.__name__, data).json()["data"]["token"]
if __name__ == '__main__':
    login = Login()
    # print(login.server_token)
